package cn.micai.base.lambda;

import java.util.Optional;

/**
 * 描述：Java 8 Optional In Depth
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/6/22 11:46
 */
public class OptionalBasicExample {

    public static void main(String [] args) {

        // 1. Optional Basic example
        Optional<String> gender = Optional.of("MALE");
        String answer1 = "Yes";
        String answer2 = null;

        System.out.println("Non-Empty Optional: " + gender);
        System.out.println("Non-Empty Optional: Gender value: " + gender.get());
        System.out.println("Empty Optional: " + Optional.empty());

        System.out.println("ofNullable on Non-Empty Optional: " + Optional.ofNullable(answer1));
        System.out.println("ofNullable on Empty Optional: " + Optional.ofNullable(answer2));

        // java.lang.NullPointerException
        System.out.println("ofNullable on Non-Empty Optional: " + Optional.of(answer2));

    }


}
